#    This is part of WeatherFront.
#
#    Copyright (C) 2010 Stefan Sieber
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#


import objc
import Foundation
import AppKit
import time

import PyFR.Utilities

import urllib2
import re
import string





verbose=1
def log(s,level=1):
	if verbose >= level:
		Foundation.NSLog( u"WeatherFrontLog: IpInfoDbDotCom: %@", s ) 
	pass

class IpInfoDbDotComCompiler:
	def __init__(self, xmlScanner):
		self = self
		self.xmlScanner = xmlScanner
		self.xmlStream = self.xmlScanner.xml_stream
		
	"""
		getCurrentLocation 
	"""
	def getCurrentLocation(self, weatherCtrl):

		value = []
		i = 0
		
		resp = ""
		resp = self.xmlScanner.getSubSet(self.xmlStream, 'Response')
		
		#log(resp)
		
		for item in (self.xmlScanner.getSubSet(resp[0], 'City'))[0]: # 
			log("City: %s" % item.get('DATA'))
			weatherCtrl.city = item.get('DATA')
		for item in (self.xmlScanner.getSubSet(resp[0], 'CountryName'))[0]: # 
			log("Country: %s" % item.get('DATA'))
			weatherCtrl.country = item.get('DATA')
		for item in (self.xmlScanner.getSubSet(resp[0], 'RegionName'))[0]: # 
			log("Region: %s" % item.get('DATA'))
			weatherCtrl.state = item.get('DATA')
		for item in (self.xmlScanner.getSubSet(resp[0], 'ZipPostalCode'))[0]: # 
			log("ZipCode: %s" % item.get('DATA'))
			weatherCtrl.zip = item.get('DATA')
			
			
		
	
		